﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace deal_h2ck.DTO
{
    public class CKhachHangDTO
    {
        string _hoTen, _email, _password, _ngaySinh, _ngayDangKy, _diaChi, _loaiKH, _sdt;
        MyCart _cart;
        public MyCart Cart
        {
            get { return _cart; }
            set { _cart = value; }
        }
        public void InitCart()
        {
            _cart = new MyCart();
        }
        public string HoTen { get { return _hoTen; } set { _hoTen = value; } }
        public string Email { get { return _email; } set { _email = value; } }
        public string Password { get { return _password; } set { _password = value; } }
        public string NgaySinh { get { return _ngaySinh; } set { _ngaySinh = value; } }
        public string NgayDangKy { get { return _ngayDangKy; } set { _ngayDangKy = value; } }
        public string DiaChi { get { return _diaChi; } set { _diaChi = value; } }
        public string LoaiKH { get { return _loaiKH; } set { _loaiKH = value; } }
        public string SDT { get { return _sdt; } set { _sdt = value; } }
        public CKhachHangDTO(string email, string password)
        {
            _email = email;
            _password = password;
        }
        public bool IsValidLogin()
        {
            string sql = "select * from USERS where Email = '" + Email.Replace("'", "''") + "' and MatKhau = '" + Password.Replace("'", "''") + "'";
            using (DataTable dt = SqlDataProvider.LoadSQL(sql))
            {
                bool ret = dt.Rows.Count > 0;
                return ret;
            }
        }
        public static CKhachHangDTO FromID(string Email)
        {
            string sql = "select * from KHACHHANG where email = '" + Email.Replace("'", "''") + "'";
            using (DataTable dt = SqlDataProvider.LoadSQL(sql))
            {
                DataRow row = dt.Rows[0];
                string matKhau = row["password"].ToString();
                CKhachHangDTO ret = new CKhachHangDTO(Email, matKhau);

                return ret;
            }
        }
    }
}